package com.hroze.util;

/**
 * 常用字符串拼接
 * 
 * @author ahoo
 * @version 0.1 build 09.12.17
 * 
 */
public class StringUtil {

	/**
	 * 拼接成ca123/456的字符串
	 * 
	 * @param s1
	 * @param s2
	 * @param divide
	 * @return
	 */
	public static String joinString(String s1, String s2, String divide) {

		if (s1 == null && s2 == null) {
			return null;
		} else if (s1 == null && s2 != null) {
			return divide + s2;
		} else if (s2 == null && s1 != null) {
			return s1 + divide;
		} else if (s1.equals(s2)) {
			return s1;
		} else if (s1.length() != s2.length()) {
			return s1.concat(divide).concat(s2);
		} else if (s1.length() == s2.length()) {
			String send = null;
			for (int i = 0; i < s1.length() && i < s2.length(); i++) {
				if (s1.charAt(i) == s2.charAt(i)) {
					continue;
				} else {
					send = s2.substring(i);
					break;
				}

			}
			return s1.concat(divide).concat(send);

		} else {
			return null;
		}

	}

	/**
	 * 对象类型的拼接字符串
	 * 
	 * @param start
	 * @param end
	 * @param divide
	 * @return
	 */
	public static String joinString(Object start, Object end, String divide) {
		String s1;
		String s2;
		if (start == null)
			s1 = null;
		else
			s1 = (String) start;
		if (end == null)
			s2 = null;
		else
			s2 = (String) end;
		return joinString(s1, s2, divide);

	}

}
